<?php

	// include the config file
	require_once("config.php");

	// firstly we need to get the OAuth token parsed by the redirect URL from google.
	
	$code = "";
	
	
	if(isset($_GET[QUERY_KEY]))
	{	
		$code = $_GET[QUERY_KEY];
	}else
	{
		// there was no token supplied so simply reqturn and error message
		echo "NO TOKEN";
		exit(1);	
	}
	
	// now we need to make the request to the google OAuth service
	
	// set up the params of the request
	
?>

<form method="post" name="Auth" action="<?php echo SERVICE_END_POINT_URI ?>">
	<table>
    	<tr>
        	<td>Code</td>
        	<td><input type="text" name="code" value="<?php echo $code ?>" /></td>
        </tr>
        <tr>
        	<td>client_id</td>
            <td><input type="text" name="client_id" value="<?php echo CLIENT_ID ?>" /></td>
        </tr>
        <tr>
        	<td>client_secret</td>
            <td><input type="text" name="client_secret" value="<?php echo CLIENT_SECRET ?>" /></td>
        </tr>
        <tr>
        	<td>redirect_uri</td>
        	<td><input type="text" name="redirect_uri" value="<?php echo LAB_URI ?>" /></td>
        </tr>
        <tr>
        	<td>grant_type</td>
            <td><input type="text" name="grant_type" value="authorization_code" /></td>
        </tr>
        <tr>
    		<td>
            	<input type="submit" value="Submit" />
    		</td>
		</tr>
    </table>
</form>
<?php
	
	/*
	$fields = array(
		CODE_KEY => urlencode($code),
		CLIENT_ID_KEY => urlencode(CLIENT_ID),
		CLIENT_SECRET_KEY => urlencode(CLIENT_SECRET),
		REDIRECT_URI_KEY => urlencode(LAB_URI),
		GRANT_TYPE_KEY => urlencode(GRANT_TYPE)
	);
	
	foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
	rtrim($fields_string,'&');
	
	$ch = curl_init();
	
	curl_setopt($ch,CURLOPT_URL,SERVICE_END_POINT_URI);
	curl_setopt($ch,CURLOPT_POST,count($fields));
	curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
	
	//execute post
	$result = curl_exec($ch);
	
	//close connection
	curl_close($ch);
	
	
	// debugging
	
	echo $result;*/

?>